package leetcode.code1380;

import java.util.ArrayList;
import java.util.List;

import leetcode.IDebug;

public class Solution implements IDebug {

	public List<Integer> luckyNumbers(int[][] matrix) {
		int m = matrix.length, n = matrix[0].length;
		int[][] mins = new int[m][2];
		int[][] maxs = new int[n][2];
		for (int i = 0; i < m; i++) {
			int min = Integer.MAX_VALUE;
			int minj = 0;
			for (int j = 0; j < n; j++) {
				int cur = matrix[i][j];
				if (cur < min) {
					min = cur;
					minj = j;
				}
				if (cur > maxs[j][0]) {
					maxs[j][0] = cur;
					maxs[j][1] = i;
				}
			}
			mins[i][0] = min;
			mins[i][1] = minj;
		}
		List<Integer> ans = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			int[] min = mins[i];
			int val = min[0];
			int col = min[1];
			if (maxs[col][1] == i) {
				ans.add(val);
			}
		}
		return ans;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
